package com.woniu.scss.controller;

import com.woniu.common.dto.XGFLDto;
import com.woniu.common.utils.PageParam;
import com.woniu.common.utils.ResponseData;
import com.woniu.scss.dto.ProductAddDTO;
import com.woniu.scss.dto.ProductDTO;
import com.woniu.scss.pojo.Product;
import com.woniu.scss.service.ProductService;
import com.woniu.scss.utils.MinioUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * packageName com.woniu.scss.controller
 *
 * @author zxyang3636
 * @version JDK 8
 * @className ProductController
 * @date 2024/8/6
 * @description TODO
 */
@RestController
@Slf4j
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private MinioUtil minioUtil;

    @PostMapping("/selProductByCondition")
    public ResponseData<?> selProductByCondition(@RequestBody PageParam<ProductDTO> pageParam) {
        return productService.selProductByCondition(pageParam);
//        log.info("pageParam:{}", pageParam);
//        return null;
    }

    @GetMapping("/selProductSort")
    public ResponseData<?> selProductSort() {
        return productService.selProductSort();
    }

    /**
     * @param : []
     * @return com.woniu.common.utils.ResponseData<?>
     * @author zxyang3636
     * @date 2024/8/7
     * {@link ResponseData<?>}
     * @description 上架
     */
    @GetMapping("/putaway")
    public ResponseData<?> putaway(@RequestParam("id") String id) {
        return productService.putaway(id);
    }

    @GetMapping("/soldOut")
    public ResponseData<?> soldOut(@RequestParam("id") String id) {
        return productService.soldOut(id);
    }

    @PostMapping("/deleteProduct")
    public ResponseData<?> deleteProduct(@RequestBody PageParam<List<Product>> pageParam) {
        return productService.deleteProduct(pageParam.getParam());
    }

    @PostMapping("/upload")
    public ResponseData<?> uploadImg(MultipartFile file) {
        try {
            return minioUtil.uploadFile(file, "img");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("/addProduct")
    public ResponseData<?> addProduct(@RequestBody ProductAddDTO productAddDTO) {
        try {
            return productService.addProduct(productAddDTO);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/selProductById")
    public ResponseData<?> selProductById(@RequestParam("productId") String productId) {
        return productService.selProductById(productId);
    }

    @PostMapping("/updateProduct")
    public ResponseData<?> updateProduct(@RequestBody ProductAddDTO productAddDTO) {
        return productService.updateProduct(productAddDTO);
    }

    @GetMapping("/productPush")
    public ResponseData<?> productPush() {
        return productService.productPush();
    }

    @PostMapping("/TBXiaJia")
    public ResponseData<?> TBXiaJia(@RequestBody List<String> productId){
        return productService.xiaJia(productId);
    }
    @PostMapping("/TBShangJia")
    public ResponseData<?> TBShangJia(@RequestBody List<String> productId){
        return productService.shangJia(productId);
    }
    @PostMapping("/TBUpdateProductType")
    ResponseData<?> TBUpdateProductType(@RequestBody XGFLDto XGFL){
        return productService.updateProductType(XGFL);
    }
    @PostMapping("/TBDeletePro")
    ResponseData<?> TBDeletePro (@RequestBody List<String> productId){
        return productService.TBDeletePro(productId);
    }
}
